<template>
  <div class="catemanager">
    <myheader title="频道管理">
      <span
        slot="left"
        class="iconfont iconjiantou2"
        @click="$router.back()"
      ></span>
    </myheader>
    <div class="mychannel">
      <h3>点击删除频道</h3>
      <div class="list">
        <span
          v-for="(v,i) in catelist"
          :key=i
          @click="delitem(v,i)"
        >{{v.name}}</span>
      </div>
    </div>
    <div class="youchannel">
      <h3>点击添加频道</h3>
      <div class="list">
        <span
          v-for="(v,i) in dellist"
          :key=i
          @click="additem(v,i)"
        >{{v.name}}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { category } from "@/apis/article.js";
import myheader from "@/components/myheader.vue";
import loginVue from "./login.vue";
export default {
  data() {
    return {
      catelist: [],
      dellist: [],
    };
  },
  components: {
    myheader,
  },
  methods: {
    delitem(v, i) {
      this.catelist.splice(i, 1);
      this.dellist.unshift(v);
      localStorage.setItem("hm_catelist", JSON.stringify(this.catelist));
      localStorage.setItem("hm_dellist", JSON.stringify(this.dellist));
    },
    additem(v, i) {
      this.dellist.splice(i, 1);
      this.catelist.unshift(v);
      localStorage.setItem("hm_catelist", JSON.stringify(this.catelist));
      localStorage.setItem("hm_dellist", JSON.stringify(this.dellist));
    },
  },
  async mounted() {
    if (localStorage.getItem("hm_catelist")) {
      this.catelist = JSON.parse(localStorage.getItem("hm_catelist"));
    } else {
      this.catelist = (await category()).data.data;
      if (localStorage.getItem("hm_toutiao")) {
        this.catelist = this.catelist.splice(2);
      } else {
        this.catelist = this.catelist.splice(1);
      }
    }
    if (localStorage.getItem("hm_dellist")) {
      this.dellist = JSON.parse(localStorage.getItem("hm_dellist"));
    }
  },
};
</script>

<style lang="less" scoped>
.mychannel,
.youchannel {
  padding: 10px;
  h3 {
    line-height: 30px;
    font-weight: bold;
  }
  .list {
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    > span {
      width: 20%;
      margin-left: 10px;
      margin-top: 10px;
      border: 1px solid #ccc;
      text-align: center;
      line-height: 40px;
    }
  }
}
</style>